package com.bzframework.example.kafka;

import com.bzframework.core.auth.Authorization;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author bingzhong
 * @Date 2025/9/15
 */
@Tag(name = "kafka测试")
@RestController
@RequestMapping("/example-kafka")
@RequiredArgsConstructor
@Authorization(ignore = true)
public class KafkaController {

    private final KafkaProducer kafkaProducer;

    @GetMapping("/send")
    @Operation(summary = "发送无key消息")
    public String sendNoKeyMessage(String topic, String message) {

        kafkaProducer.sendNoKeyMessage(topic, message);
        return topic + ":" + message;

    }

    @GetMapping("/send/key")
    @Operation(summary = "发送携带key消息")
    public String sendKeyMessage(String topic, String key, String message) {

        kafkaProducer.sendKeyMessage(topic, key, message);
        return topic + ":" + "key:" + key + ":" + message;

    }

}
